package com.budwk.app.sqfwV2.enums.dayingRoad;

import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskParamDataDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.ProblemBaseVo;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 食品安全问题9个问题
 */
@Getter
public enum FoodSupervisionRecordsEnum {

    ONE("1","isFoodBusinessLicense", "true", "是否持有效的食品经营许可证"),
    TWO("2","isBrightCertificateOperate", "true", "是否“亮证亮照”经营"),
    THREE("3","isHaveMedicalCertificate", "true", "从业人员是否有健康证明"),
    FORE("4","isRequirePersonalHygiene", "true", "从业人员个人卫生是否符合要求"),
    FIVE("5","placeInOutNeat", "true", "场所内外环境是否整洁"),
    SIX("6","isDisposalSoldWater", "true", "沽水处置是否符合要求，建立处置台账清洁"),
    SEVEN("7","isDustacilitiesAvailable", "true", "保洁、消毒设施是否符合要求"),
    EIGHT("8","isDustRodentAvailable", "true", "有无防尘、防鼠、防虫害设施"),
    NINE("9","whetherSystemProcure", "true", "是否落实食品进货查验索证索票制度、建立进货台账");

    private final String number;

    private final String code;

    private final String defaultValue;

    private final String desc;

    FoodSupervisionRecordsEnum(String number, String code, String defaultValue, String desc) {
        this.number = number;
        this.code = code;
        this.defaultValue = defaultValue;
        this.desc = desc;
    }

    /**
     * 获取问题默认值 组装ProblemBaseVo对象
     */
    public static List<ProblemBaseVo> getProblemBaseVoDefaults() {
        List<ProblemBaseVo> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> {
            ProblemBaseVo vo = new ProblemBaseVo();
            list.add(vo.setCode(e.getCode()).setDefaultValue(e.getDefaultValue()).setDesc(e.getDesc()).setNumber(e.getNumber()));
        });
        return list;
    }


    /**
     * 获取问题编号
     */
    public static FoodSupervisionRecordsEnum getEnumByCode(String code) {
        Optional<FoodSupervisionRecordsEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.orElse(null);
    }

    /**
     * 按照编号去查询
     */
    public static FoodSupervisionRecordsEnum getEnumByNumber(String number) {
        Optional<FoodSupervisionRecordsEnum> optional = Arrays.stream(values()).filter(e -> e.getNumber().equals(number)).findFirst();
        return optional.orElse(null);
    }

    /**
     * 设置默认值 并返回对象
     */
    public static List<SafeCheckTaskParamDataDTO> getAllDefaults() {
        List<SafeCheckTaskParamDataDTO> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> list.add(initData(e)));
        return list;
    }

    public static SafeCheckTaskParamDataDTO initData(FoodSupervisionRecordsEnum fEnum) {
        SafeCheckTaskParamDataDTO s = new SafeCheckTaskParamDataDTO();
        s.setFields(fEnum.getCode()).setKey(fEnum.getDefaultValue()).setRiskDesc(fEnum.getDesc()).setRiskCode(fEnum.getNumber());
        return s;
    }
}
